# -*- coding: utf-8 -*-

import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *


class MainWindow(QDialog):

    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent=parent)
        layout = QVBoxLayout()

        self.btn1 = QPushButton("Button1")
        self.btn1.setCheckable(True)
        self.btn1.toggle()
        self.btn1.clicked.connect(lambda : self.whichbtn(self.btn1))
        self.btn1.clicked.connect(self.btnstate)
        layout.addWidget(self.btn1)

        self.btn2 = QPushButton('Image')
        self.btn2.setIcon(QIcon(QPixmap("./user_128px.png")))
        self.btn2.clicked.connect(lambda : self.whichbtn(self.btn2))
        layout.addWidget(self.btn2)

        self.btn3 = QPushButton("Disabled")
        self.btn3.setEnabled(False)
        layout.addWidget(self.btn3)

        self.btn4 = QPushButton("&Download")
        self.btn4.setDefault(True)
        self.btn4.clicked.connect(lambda : self.whichbtn(self.btn4))
        layout.addWidget(self.btn4)

        self.setLayout(layout)
        self.setWindowTitle("Button Demo")

    def btnstate(self):
        if self.btn1.isChecked():
            print("Button Pressed")
        else:
            print("Button Released")

    def whichbtn(self, btn):
        print("Clicked Button is %s" % btn.text())


if __name__ == '__main__':
    app = QApplication(sys.argv)
    win = MainWindow()
    win.show()
    sys.exit(app.exec())